DAY40:Are they the "same"?


Posted by birdbirdmurmur on 2023-08-22

題目連結:

https://www.codewars.com/kata/550498447451fbbd7600041c/train/javascript

解法:

function comp(a, b) {
  if (a === null || b === null) {
    return false;
  }

  if (a.length !== b.length) {
    return false;
  }

  const sortedA = a.slice().sort((x, y) => x - y);
  const sortedB = b.slice().sort((x, y) => x - y);

  for (let i = 0; i < sortedA.length; i++) {
    if (sortedB[i] !== sortedA[i] ** 2) {
      return false;
    }
  }

  return true;
}

筆記:


#javascript #Codewars







Related Posts

[Power BI] 讀書會 #6 Power BI建立資料連結

[Power BI] 讀書會 #6 Power BI建立資料連結

安裝 Spring Boot - spring boot initializr

安裝 Spring Boot - spring boot initializr

關於 React 小書:實作 Clock 並簡介 component lifecycle 裡各個階段的作用

關於 React 小書:實作 Clock 並簡介 component lifecycle 裡各個階段的作用


Comments